package com.admin.action.login_verify_action;

import com.pojo.AdminBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@WebServlet("/registServlet")
public class RegistServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {




        String username = req.getParameter("userName");

        PrintWriter out=resp.getWriter();
        AdminBean ab=new AdminBean();
        ab.setAdminName(username);
        ResultSet rs=null;
        String sql="select * from admin where adminname=?";
        Connection conn=null;
        PreparedStatement pstm=null;
        try {
            pstm=conn.prepareStatement(sql);
            pstm.setString(1,ab.getAdminName());
            rs = pstm.executeQuery();
            if (rs.next()){
                out.print("用户名已存在");
                System.out.println("用户名已存在");
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            if (pstm!=null){
                try {
                    pstm.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }

            if (rs!=null){
                try {
                    rs.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        }
    }
}
